﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//Xna
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Puzzle_3D
{
    class Puzzle_Image
    {
        private static int TEXTUREWIDTH = 150;
        private static int TEXTUREHEIGHT = 100;

        private String imagePath;
        private String imageName;
        private int imageWidth;
        private int imageHeight;
        private Vector2 imagePosition;
        private Texture2D imageTexture;
        private Puzzle_PuzzlePiece[] puzzle;
        private Rectangle imageRectangle;
        private bool imageIsHighlighted;
        private int shownOnScreen;
        private Puzzle root;

        public Puzzle_Image(Puzzle _root, String _path, int _screenNumber)
        {
            this.root = _root;
            this.imagePath = _path;
            this.imageName = this.imagePath.Substring(this.imagePath.LastIndexOf("\\") + 1);
            this.puzzle = new Puzzle_PuzzlePiece[6];
            this.imageIsHighlighted = false;
            this.shownOnScreen = _screenNumber;
            this.loadTextureFromFile();
            this.getImageDimensions();
        }

        private void getImageDimensions()
        {
            this.imageWidth = this.imageTexture.Width;
            this.imageHeight = this.imageTexture.Height;
        }

        private void loadTextureFromFile()
        {
            this.imageTexture = Texture2D.FromFile(this.root.GraphicsDevice, this.imagePath);
        }

        public Texture2D getImageTexture()
        {
            return this.imageTexture;
        }

        public void setImageRectangle(int _x, int _y)
        {
            this.imageRectangle = new Rectangle(_x, _y, TEXTUREWIDTH, TEXTUREHEIGHT);
        }

        public int getScreenNumber()
        {
            return this.shownOnScreen;
        }

        public bool isImageHighlighted
        {
            get
            {
                return this.imageIsHighlighted;
            }
            set
            {
                this.imageIsHighlighted = value;
            }
        }

        public Vector2 ImagePosition
        {
            get
            {
                return this.imagePosition;
            }
            set
            {
                this.imagePosition = value;
            }
        }

        public String getFullImagePath()
        {
            return this.imagePath;
        }

        public void setImagePieces(Texture2D[] _pieces)
        {
            for (int i = 0; i < _pieces.Count(); i++)
            {
                this.puzzle[i] = new Puzzle_PuzzlePiece(_pieces[i], this.imageName, i);
            }
        }

        public Puzzle_PuzzlePiece getSpecificImagePiece(int _index)
        {
            return this.puzzle[_index];
        }

        public void Draw()
        {
            this.root.getSpriteBatch().Draw(this.imageTexture, this.imageRectangle, Color.White);
        }
    }
}